package DesignMode.Decorator;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}22:15
 */
public class ConcreteComponent extends Componet {
    @Override
    public void Operation() {
        System.out.println("具体对象操作");
    }


    static class ConcreteDecoratorA extends Decorator {
        private String addedState;//独有功能

        @Override
        public  void Operation() {
            super.Operation();
            //下面执行本类的功能相当于对原来的进行修饰
            addedState = "New State";
            System.out.println("具体装饰对象A的操作");
        }
    }


    static class ConcreteDecoratorB extends Decorator {
        @Override
        public void Operation() {
            super.Operation();
            AddedBehavior();
            System.out.println("具体装饰对象B的操作");
        }

        public void AddedBehavior() {

        }
    }

    static class Decorator extends Componet {//从外类来扩展Component类的功能

        private Componet componet;

        public Componet getComponet() {
            return componet;
        }

        public void setComponet(Componet componet) {
            this.componet = componet;
        }

        @Override
        public void Operation() {//实际上执行的是Componet的方法
            if (componet != null) {
                componet.Operation();
                ;
            }
        }

        public static void main(String[] args) {
            ConcreteComponent c = new ConcreteComponent();
            ConcreteDecoratorA a = new ConcreteDecoratorA();
            ConcreteDecoratorB b = new ConcreteDecoratorB();
            a.setComponet(c);
            b.setComponet(b);
            b.Operation();
        }
    }
}
